/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 */

#ifndef FILEANALYSIS_H
#define FILEANALYSIS_H

#include <wx/string.h>
#include <wx/arrstr.h>

class cbEditor;

class FileAnalysis
{
public:
           /// Default constructor (no initialisation -> call ReInit after this)
           /// 默认构造函数(无初始化->在此之后调用重新初始化(ReInit))
           FileAnalysis();
           /// Initialiasing constructor (calls ReInit)
           /// 初始化构造函数(调用ReInit)
           FileAnalysis(const wxString& FileName);
  virtual ~FileAnalysis();

  /// Has usually to be called first -> initialises the class and reads the file
  /// 通常必须先调用->初始化类并读取文件
  void ReInit(const wxString& FileName, bool verbose = false);

  /// Returns whether the file is a header file (upon file extension)
  /// 返回文件是否为头文件(根据文件扩展名)
  bool IsHeaderFile()
  { return m_IsHeaderFile; }

  /// Load the file from cbEditor or disk and splits it up into lines
  /// 从内置编辑器(cbEditor)或磁盘加载文件并将其拆分成行
  void LoadFile();

  /// Saves the file to cbEditor or disk and prepends a string (the includes)
  /// 将文件保存到内置编辑器(cbEditor)或磁盘,并在前面加上一个字符串(includes)
  void SaveFile(const wxString& Prepend);

  /// Returns whether there is another line to parse for iterators
  /// 返回是否有另一行要为迭代器解析
  bool HasMoreLines()
  { return (m_CurrentLine<m_LinesOfFile.GetCount()); }

  /// "Rewinds" the file and re-starts from the first line for iterators
  /// “倒带”文件并从迭代器的第一行重新开始
  void Rewind()
  { m_CurrentLine = 0; }

  /// Returns the nest line in a file for iterators
  /// 返回迭代器在文件中的嵌套行
  wxString GetNextLine();

  /// Detects and returns the end-of-line type of the file
  /// 检测并返回文件的行尾类型
  wxString GetEOL();

  /// Parses the file for includes and takes included header file into account
  /// 分析包含的文件,并考虑包含的头文件
  wxArrayString ParseForIncludes();

  /// Returns the include files (parsed using ParseForIncludes before)
  /// 返回包含文件(以前使用ParseForIncludes分析过)
  wxArrayString GetIncludes()
  { return m_IncludedHeaders; }

  /// Parses the file for forward declarations (only if it's a header file)
  /// 为前置声明解析文件(仅当它是头文件时)
  wxArrayString ParseForFwdDecls();

  /// Returns the forward declararions (parsed using ParseForForwardDecls before)
  /// 返回前置声明(以前使用ParseForForwardDecls分析)
  wxArrayString GetFwdDecls()
  { return m_ForwardDecls; }

  /// Returns the protocol (log) of the last operation
  /// 返回上次操作的协议(日志)
  wxString GetLog()
  { return m_Log; }

protected:
private:
  /// Internal function to reset all states (for re-initialisation).
  /// 重置所有状态的内部功能(用于重新初始化).
  void          Reset();
  //!< The editor that is being use to parse for contents
  //!< 用于分析内容的编辑器
  cbEditor*     m_Editor;
  //!< The protocol (log) of the current file analysis
  //!< 当前文件分析的协议(日志)
  wxString      m_Log;
  //!< The filename of the currently operated file
  //!< 当前操作文件的文件名
  wxString      m_FileName;
  //!< The content of the currently operated file
  //!< 当前操作的文件的内容
  wxString      m_FileContent;
  //!< The content (line-by-line) of the currently operated file
  //!< 当前操作文件的内容(逐行)
  wxArrayString m_LinesOfFile;
  //!< A list of included header files of the currently operated file
  //!< 当前操作文件的包含头文件列表
  wxArrayString m_IncludedHeaders;
  //!< A list of forward declarations of the currently operated file
  //!< 当前操作文件的前置声明列表
  wxArrayString m_ForwardDecls;
  //!< Current line in the file (used for iterators)
  //!< 文件中的当前行(用于迭代器)
  size_t        m_CurrentLine;
  //!< Be verbose in debug messages (be silent otherwise)
  //!< 在调试消息中保持详细(否则保持沉默)
  bool          m_Verbose;
  //!< Flag whether the currently operated file is a header file (upon file extension)
  //!< 标记当前操作的文件是否为头文件(根据文件扩展名)
  bool          m_IsHeaderFile;
  //!< Flag whether the currently operated has a header file
  //!< 标记当前操作是否有头文件
  bool          m_HasHeaderFile;
};

#endif // FILEANALYSIS_H
